import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: localStorage.token,
    quname: localStorage.quname,
    quid: "",
    id: Number(localStorage.id),
    zhenname: localStorage.zhenname,
    zhenid: localStorage.zhenid,
    cunname: localStorage.cunname,
    cunid: localStorage.cunid,
    name: localStorage.name,
    username: localStorage.username,
    userpassword: localStorage.userpassword,
    level: localStorage.level,
    // 区管理员登陆后保存的所有镇的信息(镇id和镇name)
    towns: [],

  },
  mutations: {
    genggaiquname(state, quname) {
      state.quname = quname;
      localStorage.quname = quname;
    },
    settoken(state, token) {
      state.token = token;
      localStorage.token = token;
    },
    setname(state, name) {
      state.name = name;
      localStorage.name = name;
    },
    setusername(state, username) {
      state.username = username;
      localStorage.username = username;
    },
    setuserpassword(state, userpassword) {
      state.userpassword = userpassword;
      localStorage.userpassword = userpassword;
    },
    // 设置管理员等级  1：区    2：镇   3：村
    setlevel(state, level) {
      state.level = level;
      localStorage.level = level;
    },
    //设置用户id
    setid(state, id) {
      state.id = id;
      localStorage.id = id;
    },
    // 设置区级的需要保存的镇信息
    settowns(state, towns) {
      state.towns = towns;
      localStorage.towns = towns;
    },
    setzhenid(state, zhenid) {
      state.zhenid = zhenid;
      localStorage.zhenid = zhenid;
    },
    setzhenname(state, zhenname) {
      state.zhenname = zhenname;
      localStorage.zhenname = zhenname;
    },
    setcunname(state, cunname) {
      state.cunname = cunname;
      localStorage.cunname = cunname;
    },
    setcunid(state, cunid) {
      state.cunid = cunid;
      localStorage.cunid = cunid;
    },
  },
  getters: {
    gettoken: (state) => {
      return state.token;
    }
  },
  actions: {},
  modules: {}
})
